/*
 * twoDimensionalPicture.cpp
 *
 *  Created on: Aug 25, 2011
 *
 */

#include "twoDimensionalPicture.h"
#include <cstdlib>
#include <iostream>
using namespace std;

twoDimensionalPicture::twoDimensionalPicture() {
	height = 10;
	width = 10;
	pixels = new int*[height];
	for (int i = 0 ; i< height ; i++){
		pixels[i] = new int[width];
	}
}
//////////////////////////////////////////////////////////
// Copy Constructor
//////////////////////////////////////////////////////////
twoDimensionalPicture::twoDimensionalPicture(const twoDimensionalPicture &source):height(height), width(width){
	for (int i = 0; i < height; i++){
		for (int j = 0; j < width; j++){
			pixels[i][j] = source.pixels[i][j];
		}
	}
}

///////////////////////////////////////////////////////////
// Overloaded Assignment
//////////////////////////////////////////////////////////
twoDimensionalPicture& twoDimensionalPicture::operator= (const twoDimensionalPicture &source){
	if (this == &source)
		return *this;
	height = source.height;
	width = source.width;
	for (int i = 0; i < height; i++){
		for (int j = 0; j < width; j++){
			pixels[i][j] = source.pixels[i][j];
		}
	}
	return *this;
}



twoDimensionalPicture::~twoDimensionalPicture() {
	delete[] pixels;
}

//////////////////////////////////////////////////////////////////////
// This method generates a random pixel matrix
// The matrix will be populated by integer values between 0 and 255
//////////////////////////////////////////////////////////////////////

void twoDimensionalPicture::generateRandomPicture() {
	for (int i = 0; i < height; i++){
		for (int j = 0; j < width; j++){
			pixels[i][j] = rand()% 256;
		}
	}
	return;
}

//////////////////////////////////////////////////////////////////
// This method will print out the integer value of the pixels
//////////////////////////////////////////////////////////////////

void twoDimensionalPicture::printPicture(){
	for(int i = 0; i < height; i++){
		for (int j = 0; j < width; j++){
			cout << pixels[i][j] << "\t";
		}
		cout << endl;
	}
}
